(deftemplate node ; un nod reprezinta o stare a problemei de cautare
(slot valA) ; cantitatea curenta din cana A
(slot valB) ; cantitatea curenta din cana B
(slot parent) ; identificatorul parintelui nodului in structura arborescenta
(slot action) ; actiunea urmatoare (umplere, varsare, mutare)
(slot type) ; nod viu (expandabil) sau mort (expandat)
(slot nr) ; identificatorul nodului
)
(deftemplate nodecount
(slot x))
(deftemplate found (slot x))
(deffacts init ; initializarea
(nodecount (x 0))
(node (valA 0) (valB 0) (parent -1) (action initial) (type alive) (nr 0)) ; primul nod
)
(reset)
(defrule check ; inlatura starile duplicat
(declare (salience 2))
?f1 <- (node (valA ?a) (valB ?b) (action ?act) (nr ?n1))
?f2 <- (node (valA ?a) (valB ?b) (action ?act) (nr ?n2))
(test (> ?n2 ?n1)) ; daca exista doua noduri cu aceleasi valori
=>
(retract ?f2) ; atunci se sterge nodul cu index mai mare (nodul aparut mai tarziu)
)
(defrule addnode ; regula care provoaca aprinderea celor 6 reguli corespunzatoare celor 6 operatii
;posinbile
(declare (salience 1))
(not (exists (found (x ?)))) ; inca nu s-a gasit o solutie
?f <- (node (valA ?a) (valB ?b) (parent ?p) (action ?act) (type alive) (nr ?n))
=>
(assert (node (valA ?a ) (valB ?b) (parent ?n) (action umple_a) (type alive) (nr (+ ?n 1))))
(assert (node (valA ?a ) (valB ?b) (parent ?n) (action umple_b) (type alive) (nr (+ ?n 2))))
    )
(run)
(facts)